﻿using Microsoft.AspNetCore.Mvc;
using MiniFox.Infrastructure;
using MiniFox.Platform;
using MiniFox.Platform.Applications.Web;
using MiniFox.Utility;
using MiniFox.Web.Infrastructure;
using Platform.Core;
using Platform.Core.Models;

namespace Platform.Web.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [NoCache, PublicAccessible]
    public class PortletController : AuthorizedController<IPortletService>
    {
        /// <summary>
        /// 获取当前我已使用的小工具
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Widgets()
        {
            var widgets = this.Component.GetMyWidgets();
            var response = widgets.CreateResponse();

            return this.ResponseResult(response);
        }
        /// <summary>
        /// 查询所有小工具
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<ResultObject<ViewTable>> Widgets([FromBody] PagedQueryObject<WidgetQuery> request)
        {
            var widgets = this.Component.Query(request);
            return widgets.CreateResponse();
        }
        /// <summary>
        /// 保存当前我使用的小工具
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Save([FromBody] string[] data)
        {
            var widgets = this.Component.Save(data);
            var response = widgets.CreateResponse();

            return this.ResponseResult(response);
        }

    }
}
